package com.goods.business.controller;


import com.goods.business.service.ConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class BizConsumerController {

    @Autowired
    private ConsumerService consumerService;

    @GetMapping("/business/consumer/findConsumerList")
    public ResponseBean<PageVO<ConsumerVO>> findConsumerList(@RequestParam Integer pageNum,
                                                             @RequestParam Integer pageSize,
                                                             ConsumerVO consumerVO
    ) {
        PageVO<ConsumerVO> list = consumerService.findConsumerList(pageNum, pageSize, consumerVO);
        return ResponseBean.success(list);
    }

    @GetMapping("/business/consumer/findAll")
    public ResponseBean<List<ConsumerVO>> findAll() {
        List<ConsumerVO> list = consumerService.findAll();
        return ResponseBean.success(list);
    }


    @PostMapping("/consumer/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO) {
        consumerService.addConsumer(consumerVO);
        return ResponseBean.success();
    }

    @GetMapping("/business/consumer/edit/{id}")
    public ResponseBean<ConsumerVO> getConsumer(@PathVariable Long id) {
        ConsumerVO consumerVO = consumerService.getConsumer(id);
        return ResponseBean.success(consumerVO);
    }

    @PutMapping("/business/consumer/update/{id}")
    public ResponseBean updateConsumer(@PathVariable Long id, @RequestBody ConsumerVO consumerVO) {
        consumerService.updateConsumer(id, consumerVO);
        return ResponseBean.success();
    }

    @DeleteMapping("/business/consumer/delete/{id}")
    public ResponseBean deleteConsumer(@PathVariable Long id) {
        consumerService.deleteConsumer(id);
        return ResponseBean.success();
    }
}

